Option Explicit On
Option Strict On

Imports NStl
Imports System.Collections.Generic
Imports NStl.Iterators
Imports NStl.SyntaxHelper


Namespace nstl.test
    Friend Class TestUtil
        Public Shared Function mismatch(Of T As IComparable(Of T))(ByVal _First1 As IInputIterator(Of T), ByVal _Last1 As IInputIterator(Of T), ByVal _First2 As IInputIterator(Of T), ByVal _Last2 As IInputIterator(Of T)) As Boolean
            Dim res As KeyValuePair(Of IInputIterator(Of T), IInputIterator(Of T)) = _
                Algorithm.Mismatch(Of T, IInputIterator(Of T), IInputIterator(Of T))(_First1, _Last1, _First2)
            Return Not ((res.Key.Equals(_Last1)) And (res.Value.Equals(_Last2)))
        End Function
        Public Shared Function mismatch(Of T As IComparable(Of T))(ByVal e1 As IEnumerable(Of T), ByVal e2 As IEnumerable(Of T)) As Boolean
            Return mismatch(e1.Begin, e1.End, e2.Begin, e2.End)
        End Function
        Public Shared Function mismatch(Of T As IComparable(Of T))(ByVal e1 As IEnumerable(Of T), ByVal ParamArray e2 As T()) As Boolean
            Return mismatch(e1, CType(e2, IEnumerable(Of T)))
        End Function

        Public Shared Function equal(Of T As IComparable(Of T))(ByVal _First1 As IInputIterator(Of T), ByVal _Last1 As IInputIterator(Of T), ByVal _First2 As IInputIterator(Of T), ByVal _Last2 As IInputIterator(Of T)) As Boolean
            Return Not mismatch(_First1, _Last1, _First2, _Last2)
        End Function
        Public Shared Function equal(Of T As IComparable(Of T))(ByVal e1 As IEnumerable(Of T), ByVal e2 As IEnumerable(Of T)) As Boolean
            Return Not mismatch(e1, e2)
        End Function
        Public Shared Function equal(Of T As IComparable(Of T))(ByVal e1 As IEnumerable(Of T), ByVal ParamArray e2 As T()) As Boolean
            Return Not mismatch(e1, e2)
        End Function
        Public Shared Function mismatch(Of Key As IComparable(Of Key), Value As IComparable(Of Value))(ByVal m As IDictionary(Of Key, Value), ByVal keys As IEnumerable(Of Key), ByVal vals As IEnumerable(Of Value)) As Boolean
            Dim k As New List(Of Key)
            Dim v As New List(Of Value)
            Algorithm.Transform(m.Begin(), m.End(), k.AddInserter(), [Select].FirstFromKeyValuePair(Of Key, Value)())
            Algorithm.Transform(m.Begin(), m.End(), v.AddInserter(), [Select].SecondFromKeyValuePair(Of Key, Value)())
            Return mismatch(k, keys) Or mismatch(v, vals)
        End Function
        Public Shared Function equal(Of Key As IComparable(Of Key), Value As IComparable(Of Value))(ByVal m As IDictionary(Of Key, Value), ByVal keys As IEnumerable(Of Key), ByVal vals As IEnumerable(Of Value)) As Boolean
            Return Not mismatch(m, keys, vals)
        End Function

        

    End Class

    Friend Class IntGenerator
        Implements INullaryFunction(Of Integer)

        Private i As Integer = 0

        Public Function execute() As Integer Implements INullaryFunction(Of Integer).Execute
            Dim ii As Integer = i
            i += 1
            Return ii
        End Function
    End Class

    Friend Class mod_int
        Implements IBinaryFunction(Of Integer, Integer, Integer)

        Public Function execute(ByVal lhs As Integer, ByVal rhs As Integer) As Integer Implements IBinaryFunction(Of Integer, Integer, Integer).execute
            Return lhs Mod rhs
        End Function
    End Class
    Friend Class abs_mod_equal
        Implements IBinaryFunction(Of Integer, Integer, Boolean)

        Public Function execute(ByVal lhs As Integer, ByVal rhs As Integer) As Boolean Implements IBinaryFunction(Of Integer, Integer, Boolean).execute
            Return Math.Abs(lhs) = Math.Abs(rhs)
        End Function
    End Class

    Friend Class plus_int
        Implements IBinaryFunction(Of Integer, Integer, Integer)

        Public Function execute(ByVal lhs As Integer, ByVal rhs As Integer) As Integer Implements IBinaryFunction(Of Integer, Integer, Integer).execute
            Return lhs + rhs
        End Function
    End Class
    Friend Class minus_int
        Implements IBinaryFunction(Of Integer, Integer, Integer)

        Public Function execute(ByVal lhs As Integer, ByVal rhs As Integer) As Integer Implements IBinaryFunction(Of Integer, Integer, Integer).execute
            Return lhs - rhs
        End Function
    End Class

    Friend Class multiplies_int
        Implements IBinaryFunction(Of Integer, Integer, Integer)

        Public Function execute(ByVal lhs As Integer, ByVal rhs As Integer) As Integer Implements IBinaryFunction(Of Integer, Integer, Integer).Execute
            Return lhs * rhs
        End Function
    End Class

    Friend Class Vec2Map
        Implements IUnaryFunction(Of Integer, System.Collections.Generic.KeyValuePair(Of Integer, String))

        Public Function execute(ByVal par As Integer) As System.Collections.Generic.KeyValuePair(Of Integer, String) Implements IUnaryFunction(Of Integer, System.Collections.Generic.KeyValuePair(Of Integer, String)).Execute
            Return New System.Collections.Generic.KeyValuePair(Of Integer, String)(par, par.ToString())
        End Function
    End Class
End Namespace

